<template>
  <div>
    <!-- 输入框 -->
    <el-input style="300px" clearable @change="getOrderList" placeholder="请输入内容" v-model="params.query" class="input-with-select">
      <el-button slot="append" icon="el-icon-search"></el-button>
    </el-input>
    <!-- 表格 -->
    <el-table height="470px" :data="orderList" border stripe style="width: 100%">
      <el-table-column type="index" label="#"></el-table-column>
      <el-table-column min-width="200px" prop="order_number" label="订单编号"></el-table-column>
      <el-table-column prop="order_price" label="订单价格"></el-table-column>
      <el-table-column width="90px" prop="order_pay" label="是否付款">
        <template slot-scope="scope">
          <el-tag :type="scope.row.pay_status==='0'?'danger':'succes'">{{scope.row.pay_status==='0'?'未付款':'已付款'}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="is_send" label="是否发货"></el-table-column>
      <el-table-column width="200px" label="下单时间">
        <template slot-scope="scope">
          {{scope.row.create_time | formatDate}}
        </template>
      </el-table-column>
      <el-table-column width="170px" label="操作">
        <template>
          <!-- 编辑 -->
          <el-button class="btn" size="small" type="primary" icon="el-icon-edit" @click="changeVisible=true"></el-button>
          <el-button class="btn" size="small" type="success" icon="el-icon-location-outline" @click="openkuaiDiVisible"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="params.pagenum" :page-sizes="[5, 10, 15, 20]" :page-size="params.pagesize" layout="total, sizes, prev, pager, next, jumper" :total="total">
    </el-pagination>
    <!-- 修改对话框 -->
    <el-dialog title="修改地区" :visible.sync="changeVisible" width="50%" @closed="changeVisibleClose">
      <el-form :model="changeForm" :rules="changeFormRule" ref="changeFormRef" label-width="100px">
        <el-form-item prop="city" label="省市县/区">
          <el-cascader v-model="
          changeForm.city" :options="cityData"></el-cascader>

        </el-form-item>
        <el-form-item prop="address" label="详细地址">
          <el-input v-model="changeForm.address"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="changeVisible = false">取 消</el-button>
        <el-button type="primary" @click="changeVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 物流对话框 -->
    <el-dialog title="物流信息" :visible.sync="kuaiDiVisible" width="50%">
      <el-timeline>
        <el-timeline-item v-for="(item, index) in kuaiDiList" :key="index" :timestamp="item.time">
          {{item.context}}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import cityD from '@/utils/citydata'
import kuaidiData from '@/utils/kuaidiData'
export default {
  name: 'order',
  data() {
    return {
      params: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      orderList: [],
      kuaiDiList: [],
      total: 0,
      changeVisible: false,
      kuaiDiVisible: false,
      changeForm: {
        city: '',
        address: ''
      },
      changeFormRule: {
        city: [{ required: true, message: '请选择地区', trigger: 'blur' }],
        address: [{ required: true, message: '请输入详细地址', trigger: 'blur' }]
      },
      cityData: cityD,
      // 物流单号
      kuaiDiNum: 1106975712662
    }
  },
  methods: {
    async getOrderList() {
      const { data: res } = await this.$api.order.getOrdersApi(this.params)
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.orderList = res.data.goods
      this.total = res.data.total
    },
    // 获取物流信息
    getKuaiDiList() {
      // 模拟获取到数据

      if (kuaidiData.meta.status !== 200) {
        this.$message.error('获取失败')
      }
      this.$message.success('获取成功')
      this.kuaiDiList = kuaidiData.data
      console.log(this.kuaiDiList)
    },
    // 分页大小
    handleSizeChange(val) {
      this.params.pagesize = val
      this.getOrderList()
    },
    // 分页数量
    handleCurrentChange(val) {
      this.params.pagenum = val
      this.getOrderList()
    },
    // 对话框关闭
    changeVisibleClose() {
      this.$refs.changeFormRef.resetFields()
    },
    // 打开物流对话框
    openkuaiDiVisible() {
      this.getKuaiDiList()
      this.kuaiDiVisible = true
    }
  },
  created() {
    console.log(this.cityData)
    this.getOrderList()
  }
}
</script>

<style lang="less" scoped>
.el-table {
  margin-top: 15px;
}
.btn {
  width: 50px;
}
.el-cascader {
  width: 100%;
}
</style>
